<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Index extends CI_Controller {

	public $data 	= 	array();
 
	public function __construct() {
 
		//parent::Controller();
		parent::__construct(); //for CI 2.x users
 
		$this->load->module_model('store', 'store_model', 'store');
		$this->load->library('basic_library');
		$this->load->helper('text');
	}
 
	public function index() 
	{
		/*$this->load->library('sitemaps');
		$posts = $this->store->get_id_category_sitemap();
		var_dump($posts);
		foreach($posts AS $post)
        {
            $item = array(
                "loc" => site_url("/store/product/category/" . $post->slug),
                // ISO 8601 format - date("c") requires PHP5
                "lastmod" => date("c", strtotime($post->last_modified)),
                "changefreq" => "hourly",
                "priority" => "0.8"
            );
            var_dump($item);
            $this->sitemaps->add_item($item);
        }

        $file_name = $this->sitemaps->build("sitemap_blog.xml");
        $reponses = $this->sitemaps->ping(site_url($file_name));
        redirect(site_url($file_name));*/
		
		$data['ItemID'] = 'Store';
		$data['title'] = 'Game Store - Game Categories';
		$data['description'] = 'Game Store - Word of application games, download free game. More game for mobile, ipad, ios, android';
 		$data['categories'] = $this->store->get_all_category();
		$this->_template['page']	= 'store/home';
		$this->system_library->load($this->_template['page'], $data);
 
	}
	
	public function category($id = null)
	{
		$this->load->library('pagination');
		$config = array();
		$config['base_url'] = base_url().'store/product/category/'.$id;
		$config['total_rows'] = $this->store->count_all_product($id);
		//echo $config['total_rows'];
		$config['per_page'] = 20;
		$config['uri_segment'] = 5;
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(5))? $this->uri->segment(5):0;
		
		$data['ItemID'] = 'Category';
		$data['title'] = $this->basic_library->get_category_name($id);
		$data['description'] = character_limiter($this->basic_library->get_category_description($id), 160);
		$data['products'] = $this->store->get_product_of_category($id,$config['per_page'], $page);
		$data['iphoneproducts'] = $this->store->get_iphoneproduct_of_category($id,$config['per_page'], $page);
		$data['links'] = $this->pagination->create_links();
		$this->_template['page']	= 'store/category';
		$this->system_library->load($this->_template['page'], $data);
	}
	
	public function detail($id = null)
	{
		$data['ItemID'] = 'View';
		$data['title'] = $this->basic_library->get_product_name($id);
		$data['description'] = character_limiter($this->basic_library->get_product_description($id), 160);
		$data['relateditems']	=	$this->store->get_related_items($id);
		$data['productinfo'] = $this->store->get_product($id);
		$this->store->update_hit($id);
		$this->_template['page']	= 'store/detail';
		$this->system_library->load($this->_template['page'], $data);
	} 
}

/* End of file welcome.php */
/* Location: ./application/controllers/product.php */